#include<stdio.h>
#include<stdlib.h>

//------------------------------------------------------------------------------------------------------------------------
//	Eingangsbyte von I2C nach FHEM schreiben
//------------------------------------------------------------------------------------------------------------------------
void EbytetoFHEM(int hexaDecimal,int Ebyte, int EoA )
{
	for(int i =7; i >= 0 ; i--)
	{
		char toFHEM[100] = {0};
		// conditionales if  = on/off
		// echo muss im bash sein, da sonst nur im sh!!!
		sprintf(toFHEM,"bash -c \"echo set %dB%d_Bit%d %s > /dev/tcp/localhost/7072\"",EoA,Ebyte,i,((1<<i)&hexaDecimal)?"on":"off");
		system(toFHEM);

#if 0
		if((1<<i)&hexaDecimal){
			sprintf(toFHEM,"bash -c \"echo set EB%d_Bit%d on > /dev/tcp/localhost/7072\"",Ebyte,i);
			system(toFHEM);
			printf("1");
			}
		else{
			sprintf(toFHEM,"bash -c \"echo set EB%d_Bit%d off > /dev/tcp/localhost/7072\"",Ebyte,i);
			//sprintf(toFHEM,"echo test0; perl /opt/fhem/fhem.pl 7072 \"set EB%d_Bit%d off\"; echo testende0",Ebyte,i);
			system(toFHEM);
			printf("0");
			}
#endif
	}

}

//-----------------------------------------------------------------------------------------------------------------------
//	Ausgangsbyte von FHEM nach I2C schreiben
//-----------------------------------------------------------------------------------------------------------------------
void AbytefromFHEM(int Abyte,int EoA)
{
	for(int i = 7; i>=0 ; i--)
	{
		char toI2C[100] = {0};
//		sprintf(toI2C,"bash -c \"echo getstate %dB%d_Bit%d > /dev/tcp/localhost/7072\"",EoA,Abyte,i);
//		int state = system(toI2C);
//		printf("Bit%d \n",i);
//		printf("state = %d \n",state);
	}
}









